{{- define "operator_trivy_report_updater" }}
cpu: 50m
memory: 50Mi
{{- end }}

{{ $dictRepository := printf "%s/security/trivy-bdu:1" .Values.global.modulesImages.registry.base | quote }}

{{- if .Values.operatorTrivy.linkCVEtoBDU }}

{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: report-updater
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "report-updater")) | nindent 2 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: report-updater
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: report-updater
      minAllowed:
        {{- include "operator_trivy_report_updater" . | nindent 8 }}
      maxAllowed:
        cpu: 100m
        memory: 100Mi
{{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: report-updater
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "report-updater")) | nindent 2 }}
spec:
  replicas: {{ include "helm_lib_is_ha_to_value" (list . 2 1) }}
  revisionHistoryLimit: 2
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: report-updater
  template:
    metadata:
      labels:
        app: report-updater
    spec:
      imagePullSecrets:
      - name: deckhouse-registry
      serviceAccountName: report-updater
      automountServiceAccountToken: true
      {{- include "helm_lib_node_selector" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_priority_class" (tuple . "cluster-low") | nindent 6 }}
      {{- include "helm_lib_module_pod_security_context_run_as_user_nobody" . | nindent 6 }}
      containers:
      - name: report-updater
        {{- include "helm_lib_module_container_security_context_read_only_root_filesystem_capabilities_drop_all" . | nindent 8 }}
        image: {{ include "helm_lib_module_image" (list . "reportUpdater") }}
        env:
        - name: DICTIONARY_OCI_IMAGE
          value: {{ $dictRepository }}
        volumeMounts:
        - mountPath: /etc/ssl/report-updater
          name: report-updater-webhook-ssl
        - mountPath: /root/.docker
          name: docker-config
          readOnly: true
        ports:
          - name: https
            containerPort: 40443
        livenessProbe:
          httpGet:
            path: /healthz
            port: 40443
            scheme: HTTPS
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          failureThreshold: 6
        resources:
          requests:
            {{- include "helm_lib_module_ephemeral_storage_only_logs" . | nindent 12 }}
{{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
            {{- include "operator_trivy_report_updater" . | nindent 12 }}
{{- end }}
      volumes:
      - name: report-updater-webhook-ssl
        secret:
          secretName: report-updater-webhook-ssl
      - name: docker-config
        secret:
          defaultMode: 420
          items:
          - key: .dockerconfigjson
            path: config.json
          secretName: deckhouse-registry
{{- end }}
